<?php

/******************************************
 * File:			lib_show.php
 * Version:			1.0.1
 * Last modified:	21/10/2009
 * Last modifier:	Hugo Lavigne
 *****************************************/

 Function show()
{	
	imports("webadmin.templates.get_templates");
	
	if (@$_SESSION['status'] == "offline")
	{
		if (!is_administrator(@$_SESSION['uid']))
		{
			if (@$_SESSION['page'] != "login")
			{
				redirect("login.php?err=3", 1);
				exit;
			}
		}
	}
	else
	{
		if (!file_exists("./data/config/install.php"))
			check();
	}
	
	if ($_SESSION['valid'] == "ok")
	{
		if (file_exists($_SESSION['current_path']."/template/design.php"))
			include ($_SESSION['current_path']."/template/design.php");
		else
		{
			if (file_exists($_SESSION['path_templates']."/".$_SESSION['template']."/design.php"))
				include ($_SESSION['path_templates']."/".$_SESSION['template']."/design.php");
			else
			{
				$_SESSION['template'] = get_template_default();
				include ($_SESSION['path_templates']."/".$_SESSION['template']."/design.php");
			}
		}
	}
	else
	{
		if (file_exists("data/config/install.php"))
		{
			$_SESSION['template'] = "default";
			include ($_SESSION['path_templates']."/".$_SESSION['template']."/design.php");
		}
		else
		{
			if (file_exists($_SESSION['current_path']."/template/design.php"))
				include ($_SESSION['current_path']."/template/design.php");
			else
			{
				$_SESSION['template'] = get_template_default();
				include ($_SESSION['path_templates']."/".$_SESSION['template']."/design.php");
			}
		}
	}
	
  return;
}

Function check_rights_module($mod)
{
	$uids_ok = get_ids_ok($mod, "uid");
	$gids_ok = get_ids_ok($mod, "gid");
	
	$flag = "ko";
	
	if ($uids_ok != -1)
	{
		$nb = count($uids_ok);
		$i = 0;
		while ($i < $nb)
		{
			if ($uids_ok[$i] == @$_SESSION['uid'])
			{
				$flag = "ok";
				break;
			}
			$i++;
		}
	}
	
	if ($flag == "ko")
	{
		if ($gids_ok != -1)
		{
			$nb = count($gids_ok);
			$i = 0;
			while ($i < $nb)
			{
				if (is_in_group($gids_ok[$i], @$_SESSION['uid']))
				{
					$flag = "ok";
					break;
				}
				$i++;
			}
		}
	}
	
	if (!is_administrator(@$_SESSION['uid']))
	{
		if (($uids_ok != -1) || ($gids_ok != -1))
		{
			if ($flag == "ko")
				return (FALSE);
		}
	}
	return (TRUE);
}

Function make_menu()
{	
	@$table_modules = $_SESSION['prefix']."modules";
	$req = dbquery("SELECT mid,name,path,actif,name_a,name_l,show_a,show_l,link_a,link_l FROM $table_modules WHERE 1 ORDER BY place ASC");
	
	if (@mysql_num_rows($req) == 0)
		return;
	while ($line = mysql_fetch_array($req))
	{
		if ($line['actif'] == "ok")
		{
			if ($_SESSION['login'] == "")
			{
				if ($line['show_a'] == "ok")
				{
					if (check_rights_module($line['path']))
						Print("<li><a href=\"$line[link_a]\">$line[name_a]</a></li>");
				}
			}
			else
			{
				if ($line['show_l'] == "ok")
				{
					if (check_rights_module($line['path']))
						Print("<li><a href=\"$line[link_l]\">$line[name_l]</a></li>");
				}
			}
		}
	}
	
	if (is_actif_mod("signup"))
	{
		if (isset($_SESSION['uid']))
			Print("<li><a href=\"login.php?action=deco\"><img src=\"$_SESSION[path_images]/login/out_1.png\" width=13 height=13> Deconnexion</a></li>");
		else
			Print("<li><a href=\"login.php\"><img src=\"$_SESSION[path_images]/login/connect_1.png\" width=14 height=14> Connexion</a></li>");
	}
	
	return;
}

?>